﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mindfor.Web.Routing
{
	/// <summary>
	/// Assigns a URL route to an MVC Controller class method.
	/// </summary>
	[AttributeUsage(AttributeTargets.Method, Inherited=true, AllowMultiple=true)]
	public class UrlRouteAttribute : Attribute
	{
		/// <summary>
		/// Gets or sets route index. It is used to determine routes orders in one action.
		/// If action has only one route than route index can be 0.
		/// </summary>
		public int RouteIndex { get; set; }

		/// <summary>
		/// Gets or sets optional name of the route.
		/// Route names must be unique per route.
		/// </summary>
		public string Name { get; set; }

		/// <summary>
		/// Gets or sets optional path of the URL route.
		/// This path is relative to the root of the web site.
		/// If this property is set then path path will be ignored.
		/// Do not append a "/" prefix. Specify empty string for the root page.
		/// </summary>
		public string Path { get; set; }

		/// <summary>
		/// Gets or sets optional sub path of the URL route.
		/// Sub path is added to the end page path.
		/// If sub path is null then action name is added.
		/// </summary>
		public string SubPath { get; set; }

		/// <summary>
		/// Assigns a URL route to an MVC Controller class method.
		/// </summary>
		public UrlRouteAttribute()
		{
		}

		/// <summary>
		/// Assigns a URL route to an MVC Controller class method.
		/// </summary>
		/// <param name="routeIndex">Route index. It is used to determine routes orders in one action.
		/// If action has only one route than route index can be null.</param>
		/// <param name="subPath">Sub path of the URL route.</param>
		public UrlRouteAttribute(int routeIndex, string subPath)
		{
			RouteIndex = routeIndex;
			SubPath = subPath;
		}

		/// <summary>
		/// Assigns a URL route with index 0 to an MVC Controller class method.
		/// </summary>
		/// <param name="subPath">Sub path of the URL route.</param>
		public UrlRouteAttribute(string subPath)
			: this(0, subPath)
		{
		}
	}
}
